<?php
class links {
	var $base_url;
	var $userPerm;
	var $user_id;
	
	function makeLink ($link){
		if(is_object($link)){
			if($link->type != 'url')
			{
				return $this->base_url.'page/'.$link->id;
			}else{
				return $link->key;
			}
		}else{
			return $this->base_url.$link;
		}
	}

	function menu ($menu,$show = 1,$catInfo = FALSE){
		if (count($menu) > 0)
		{
			foreach ($menu as $link)
			{?>
			<dl<?
				if(is_object($catInfo))
					if($catInfo->id == $link->id || $catInfo->cat == $link->id){
						echo ' class="select"';
					}
			?>>
				<dt><a href='<?=$this->makeLink($link)?>' <?if($link->type == 'url')echo 'target="_blank"';?> ><?=$link->title?></a><?
					if( $this->userPerm->checkPerm( $this->user_id,'re', $link->id) ){
						echo '&nbsp;<span class="menuControl" title="'.$link->id.'">';
						if($link->type != 'url')
							echo '<a class="ui-state-default ui-corner-all" href="'.$this ->makeLink('adm/admmenu/add/'.$link->id).'" title="Добавить под-меню">
																			<span class="ui-icon ui-icon-plus">&nbsp;</span></a>';
						echo '<a class="ui-state-default ui-corner-all" href="'.$this ->makeLink('adm/admmenu/edit/'.$link->id).'" title="Редактировать меню">
																			<span class="ui-icon ui-icon-pencil">&nbsp;</span></a>
							<a class="ui-state-default ui-corner-all" href="'.$this ->makeLink('adm/admmenu/remove/'.$link->id).'" title="Удалить меню">
																			<span class="ui-icon ui-icon-minus">&nbsp;</span></a>
							</span>&nbsp;';
					}
					?></dt>
			</dl>
			<?}
		}
	}
	function menuSelect ($menu,$mid,$sub = FALSE){
		if (count($menu) > 0)
		{
			foreach ($menu as $link)
			{
				if($link->type != 'url') {
					$class = 'ui-widget-content';

					if($mid == $link->id)
						$class .= ' ui-selected';
					if($sub)
						$class .= ' subMenu';

					echo '<li class="'.$class.'" title="'.$link->id.'">'.$link->title.'</li>';
					if(is_array($link->subMenu)){
						$this->menuSelect($link->subMenu,$mid,TRUE);
					}
				}
			}
		}
	}
}
/* End of file header.php */
/* Location: ./system/application/views/inc/menu.php */
?>
